/*
 *  Copyright 2010 BeTo.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

/*
 * EditAlbumDialog.java
 *
 * Created on 08-mar-2010, 9:08:47
 */

package edu.upf.userinterface.impl;

import javax.swing.ButtonModel;

/**
 *
 * @author BeTo
 */
public class EditAlbumDialog extends javax.swing.JDialog {

    private String newname;
    private boolean delete = false;
    /** Creates new form EditAlbumDialog */
    public EditAlbumDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationByPlatform(true);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        AcceptButton = new javax.swing.JButton();
        nameBox = new javax.swing.JCheckBox();
        deleteBox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("editAlbum");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jLabel1.setText("Choose an option:");

        AcceptButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/accept20px.png"))); // NOI18N
        AcceptButton.setText("Accept");
        AcceptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AcceptButtonActionPerformed(evt);
            }
        });

        buttonGroup.add(nameBox);
        nameBox.setText("Change name.");

        buttonGroup.add(deleteBox);
        deleteBox.setText("Delete album.");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(39, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(12, 12, 12)
                        .add(AcceptButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(nameBox)
                    .add(deleteBox)
                    .add(jLabel1))
                .add(43, 43, 43))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jLabel1)
                .add(18, 18, 18)
                .add(nameBox)
                .add(2, 2, 2)
                .add(deleteBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(AcceptButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AcceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AcceptButtonActionPerformed
        if (nameBox.isSelected()){
            this.setVisible(false);
            ChangeAlbumNameDialog cn = new ChangeAlbumNameDialog(new java.awt.Frame(), true);
            newname = cn.getNewName();
            this.dispose();
        }else if (deleteBox.isSelected()){
            delete = true;
            this.dispose();
        }
}//GEN-LAST:event_AcceptButtonActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        this.dispose();
    }//GEN-LAST:event_formWindowClosing

    public boolean isDelete(){
        return delete;
    }

    public boolean isNewName(){
        return newname != null;
    }

    public String getNewName(){
        return newname;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AcceptButton;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JCheckBox deleteBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JCheckBox nameBox;
    // End of variables declaration//GEN-END:variables

}
